home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / ACGIFREE.ZIP / SAMPLES / CGI_EX.CPP next >
Encoding:
C/C++ Source or Header  |  1996-09-09  |  2.7 KB  |  88 lines

  1. ////////////////////////////////////////
  2. //
  3. //  Sample CGI program
  4. //
  5. //    Call it like: http://www.myserver.net/mycgi/path cgi_ex.exe?MSG=Hello&LOC=World
  6. //      the extension can be .cgi, .exe or whatever, depending on your server      
  7. //
  8. //    You can also create an HTML page with a FORM submission and use this to test
  9. //      what you are supposed to receive.
  10. //
  11.  
  12. #define _DEBUG_DUMP_          //a_Enable for extended output (non-shareware version)
  13. //#define _WIN32_TEST_          //a_Enable for local debugging
  14.  
  15. #include "a_acgi.h"
  16.  
  17. int main()
  18. {
  19.  
  20.   #ifdef _WIN32_TEST_
  21.     char *pcTest=aStrDup("Item0=%0D%0ATest0&Submit=1&Another=Item&A=8398723498");
  22.   #endif
  23.  
  24.   ACGI cgiOut;
  25.  
  26.   //a_Get all possible form items usinf POST, GET or both
  27.   #ifdef _WIN32_TEST_
  28.     cgiOut.cgiGetFormItems(pcTest);
  29.   #else
  30.     cgiOut.cgiGetFormItems();
  31.   #endif
  32.  
  33.   //a_Start the HTML page
  34.   cgiOut.mimeHTML();                      //a_First ever thing to a browser is a MIME directive
  35.   cgiOut.htmlStartHTML();                 //a_Start the HTML page
  36.   cgiOut.htmlDoHEAD("Sample CGI form");   //a_Do the HEAD and TITLE in one
  37.   
  38.   //a_Start the <BODY>
  39.   cgiOut.htmlStartBODY();
  40.  
  41.   //a_Output
  42.   cgiOut.htmlStartTag("H1", "ALIGN=CENTER");
  43.   cgiOut << "FORM Submission Items";
  44.   cgiOut.htmlEndTag("H1");
  45.  
  46.   //a_Form items... doOut is implemented in APairList
  47.   //a_doOut accepts AStreamOutput which is a grand-parent of ACGI,
  48.   //a_so as it turns out it works on itself...
  49.   //a_The output is formatted just like a list of CGI parameters.
  50.   //
  51.   //a_Ok, here is a silly example of what this means in real life,
  52.   //a_You are using something that you learned from your mother and applying
  53.   //a_it to something learned from your father...
  54.   //a_Sort of like sewing up a camping tent?!? :)
  55.   cgiOut << "<P><H2>As submitted</H2><BR>";
  56.   cgiOut.doOut(&cgiOut);
  57.   cgiOut.htmlStartTag("HR");
  58.   cgiOut.htmlStartTag("BR");
  59.   
  60.   //a_Now use the methods in ACGI inherited from both AHTML and AFormList
  61.   //a_to display the list contents
  62.   cgiOut << "<P><H2>After parsing</H2><BR>";
  63.   if (cgiOut.lGetCount() > 0x0)
  64.   {
  65.     cgiOut.htmlStartTag("PRE");
  66.     cgiOut.doPairs(&cgiOut, ' ', 0x1, 0x0, 0x0); //a_Unquoted, 1 per line, URL unencoded
  67.     cgiOut.htmlEndTag("PRE");
  68.   }
  69.   else
  70.     cgiOut << "No FORM items were submitted.<BR>" << endl;
  71.  
  72.   //a_Single tags can use Start for <tag>, without ever calling the end which does </tag>...
  73.   cgiOut.htmlStartTag("HR");
  74.   cgiOut.htmlStartTag("BR");
  75.   
  76.   //a_Dump the environment
  77.   cgiOut.cgiEnvironmentDump();
  78.   
  79.   //a_The End...
  80.   cgiOut.htmlEndBODY();
  81.   cgiOut.htmlEndHTML();
  82.  
  83.   #ifdef _WIN32_TEST_
  84.     delete []pcTest;
  85.   #endif
  86.  
  87.   return 1;
  88. }